<template>
<div>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible">
    <el-form :model="inputForm" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             label-width="120px">
      <el-row  :gutter="15">

        <el-col :span="12">
          <el-form-item label="转发次数" prop="transpond"
                        :rules="[
                 ]">
<!--            <el-input v-model="inputForm.transpond" placeholder="请填写转发次数"     ></el-input>-->
            <el-input-number v-model="inputForm.transpond" label="请填写转发次数"></el-input-number>
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="发布次数" prop="publish" :rules="[]">
<!--            <el-input v-model="inputForm.publish" placeholder="请填写发布次数"     ></el-input>-->
            <el-input-number v-model="inputForm.publish" label="请填写发布次数"></el-input-number>
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="收藏次数" prop="collect" :rules="[]">
<!--            <el-input v-model="inputForm.collect" placeholder="请填写收藏次数"     ></el-input>-->
            <el-input-number v-model="inputForm.collect" label="请填写收藏次数"></el-input-number>
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="开始时间" prop="startTime" :rules="[]">
<!--            <el-input v-model="inputForm.startTime" placeholder="请填写开始时间"     ></el-input>-->
            <el-date-picker
              v-model="inputForm.startTime"
              type="datetime"
              format="yyyy-MM-dd HH:mm:ss"
              value-format="yyyy-MM-dd HH:mm:ss"
              placeholder="请填写开始时间">
            </el-date-picker>
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="结束时间" prop="overTime"
                        :rules="[
                 ]">
<!--            <el-input v-model="inputForm.overTime" placeholder="请填写等级名称"     ></el-input>-->
            <el-date-picker
              v-model="inputForm.overTime"
              type="datetime"
              format="yyyy-MM-dd HH:mm:ss"
              value-format="yyyy-MM-dd HH:mm:ss"
              placeholder="请填写等级名称">
            </el-date-picker>
          </el-form-item>
        </el-col>

        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">关闭</el-button>
      <el-button type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          transpond: 0,
          publish: 0,
          collect: 0,
          startTime: null,
          overTime: null
        }
      }
    },
    components: {
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建活动表`
        } else if (method === 'edit') {
          this.title = '修改活动表'
        } else if (method === 'view') {
          this.title = '查看活动表'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.$http({
              url: `/activityinfo/activityInfo/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.activityInfo)
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/activityinfo/activityInfo/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              this.loading = false
              if (data && data.success) {
                this.visible = false
                this.$message.success(data.msg)
                this.$emit('refreshDataList')
              }
            })
          }
        })
      }
    }
  }
</script>
